package db.views;

import java.sql.SQLException;

import org.hsqldb.Types;

import db.DBObject;
import db.tables.DBCountryTable;
import db.tables.DBTownTable;

public class DBTownView extends DBObject {
	public static final String TABLE_NAME="town_view";
	
	public static final String TOWN_ID_COL = DBTownTable.TOWN_ID_COL,
			TOWN_NAME_COL = DBTownTable.TOWN_NAME_COL,
			POSTAL_CODE_COL= DBTownTable.POSTAL_CODE_COL,
			COUNTRY_NAME_COL=DBCountryTable.COUNTRY_NAME_COL;
	
	protected static final String statement ="SELECT "+TOWN_ID_COL+","+TOWN_NAME_COL+","+POSTAL_CODE_COL+","
		+COUNTRY_NAME_COL+" FROM "+DBTownTable.TABLE_NAME+" JOIN "+ DBCountryTable.TABLE_NAME+" ON ("
		+getAbsoluteColumn(DBTownTable.TABLE_NAME, DBTownTable.COUNTRY_ID_COL)+" = "
		+getAbsoluteColumn(DBCountryTable.TABLE_NAME, DBCountryTable.COUNTRY_ID_COL)+");";

	public DBTownView() throws ClassNotFoundException, SQLException {
		super(TABLE_NAME, new Object[][] {
				{ TOWN_ID_COL, Types.BIGINT, "", "" },
				{ TOWN_NAME_COL, Types.VARCHAR, "", "" },
				{ POSTAL_CODE_COL, Types.INTEGER, "", "" },
				{ COUNTRY_NAME_COL, Types.VARCHAR,"","" }},statement);
	}
	
//	public void insert(String town_name,int postal_code,String country_name){
//		String[] columns={};
//		Object[] values={};
//		Long pk=insertGetPK(columns, values);
//	}
}
